﻿
<div class="weui-cells weui-cells_form">
    <div class="weui-cell">
        <div class="weui-cell__hd">
            <label class="weui-label">姓名</label>
        </div>
        <div class="weui-cell__bd">
            <input class="weui-input" id="name" type="text" placeholder="请填写您的真实姓名" />
        </div>
    </div>
    <div class="weui-cell">
        <div class="weui-cell__hd"><label class="weui-label">手机号</label></div>
        <div class="weui-cell__bd">
            <input class="weui-input" id="account" type="tel" placeholder="请填写您的手机号码" />
        </div>
    </div>
    <div class="weui-cell weui-cell_vcode">
        <div class="weui-cell__hd">
            <label class="weui-label">验证码</label>
        </div>
        <div class="weui-cell__bd">
            <input class="weui-input" type="number" id="code" placeholder="请输入短信验证码">
        </div>
        <div class="weui-cell__ft">
            <a href="javascript:;" class="weui-vcode-btn" onclick="senmobile(60);" id="get_code">获取验证码</a>
        </div>
    </div>
    <div class="weui-cell  weui-cell_vcode">
        <div class="weui-cell__hd"><label for="" class="weui-label">所在院校</label></div>
        <div class="weui-cell__bd">
            <input class="weui-input" type="text" id="schoolInput" value="" onclick="selectSchool();" placeholder="请选择" />
            <input type="hidden" id="hidForSchoolID"/>
        </div>
        <div class="weui-cell__ft">
            <a href="javascript:;" class="weui-vcode-btn " onclick="selectSchool();" id="">选择学校</a>
        </div>
    </div>
    <div class="weui-cell  weui-cell_vcode">
        <div class="weui-cell__hd"><label for="" class="weui-label">所在院系</label></div>
        <div class="weui-cell__bd">
            <input class="weui-input" type="text" id="collegeInput" value="" placeholder="请选择或填写" />
            <input type="hidden" id="hidForCollegeID" />
        </div>
        <div class="weui-cell__ft">
            <a href="javascript:;" class="weui-vcode-btn " onclick="selectCollege();" id="">选择院系</a>
        </div>
    </div>

</div>
<div class="weui-btn-area">
    <a class="weui-btn weui-btn_primary" onclick="getHashCode()" id="showTooltips">申请邀请码</a>
</div>
<div class="weui-cells__tips" style="text-align: center;">目前仅支持教师用户申请邀请码注册为平台用户</div>



<script type="text/javascript">


    var issend = true;
    function senmobile(t) {
        if (issend) {
            //验证电话号码手机号码
            var phoneObj = document.getElementById('account');

            if (phoneObj.value != "") {
                var phoneVal = phoneObj.value;
                var p1 = /^(0|86|17951)?(13[0-9]|15[012356789]|17[678]|18[0-9]|14[57])[0-9]{8}$/;
                var me = false;
                if (p1.test(phoneVal)) me = true;
                if (!me) {
                    phoneObj.value = '';
                    weui.topTips('请输入正确的手机号码');
                    phoneObj.focus();
                    return false;
                } else {
                    issend = false;
                    var url = "@Url.Action("GetSMS", "Api")?mobile="+phoneVal;
                  
                    axios.get(url)
                     .then(function (response) {
                         if (response.status == 200) {
                             weui.toast("验证码发送成功");
                             for (var i = 1; i <= t; i++) {
                                 window.setTimeout("update_a(" + i + "," + t + ")", i * 1000);
                             }
                         }
                     })
                    .catch(function (error) {
                        console.log(error);
                    });
                }
            } else {
                weui.topTips('手机号码不能为空！');
                return false;
            }
        }
    }
    function update_a(num, t) {

        var uCode = document.getElementById('get_code');
        if (num == t) {
            uCode.innerHTML = " 重新发送 ";
        }
        else {
            var printnr = t - num;
            uCode.innerHTML = printnr + " 秒后重发";
        }
    }

    function selectSchool() {
        layer.open({
            type: 2,
            title: '选择学校',
            shadeClose: true,
            shade: 0.8,
            area: ['100%', '100%'],
            content: '@Url.Action("SelectSchool")' //iframe的url
        });
    }
    //选择院系
    function selectCollege() {
        var schoolId = $("#hidForSchoolID").val();
        if (schoolId == "") {
            weui.topTips('请先选择学校！');
            return;
        }
        layer.open({
            type: 2,
            title: '选择院系',
            shadeClose: true,
            shade: 0.8,
            area: ['100%', '100%'],
            content: '@Url.Action("SelectCollege")？school='+schoolId //iframe的url
        });
    }
    //选择学校的回调函数
    function schoolCallback(id,name) {
        $("#schoolInput").val(name);
        $("#hidForSchoolID").val(id);
        layer.closeAll();
    }
    //选择院系的回调函数
    function collegeCallback(id, name) {
        $("#collegeInput").val(name);
        $("#hidForCollegeID").val(id);
        layer.closeAll();
    }
    //申请邀请码
    function getHashCode() {
        var name = $("#name").val();//姓名
        var mobile = $("#account").val();//手机号
        var school_id = $("#hidForSchoolID").val();//学校ID
        var college_id = $("#hidForCollegeID").val();//学院ID
        var new_college_name = $("#collegeInput").val();//学院名称 
        var verify_code = $("#code").val(); //邀请码
        if (name == "") {
            weui.topTips("请填写姓名");
            return;
        }
        if (mobile == "") {
            weui.topTips("请填写手机号");
            return;
        }
        if (school_id == "") {
            weui.topTips("请填写学校");
            return;
        }
        if (new_college_name == "") {
            if (college_id == "") {
                weui.topTips("请填写院系");
                return;
            }
        }
        if (verify_code == "") {
            weui.topTips("请填写邀请码");
            return;
        }

        var url = "";
        //参数
        var params = {
            name: name,
            mobile: mobile,
            school_id: school_id,
            college_id: college_id,
            new_college_name: new_college_name,
            verify_code: verify_code
        };
        axios.post(url,params,{headers: {
                'Access-Control-Allow-Origin':'*'
            }})
         .then(function (response) {
             console.log(response);
         })
        .catch(function (error) {
            console.log(error);
        });

    }

</script>
